package mq

import (
	"charging_pile/devices/internal/svc"
	"charging_pile/util/protocol/jiuxing"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

var channel0C = make(chan *jiuxing.Package, 1000)

func handle0C(nc *natsClient, in *jiuxing.Package) (jxMsg *jiuxing.Package) {
	channel0C <- in
	resp := jiuxing.Msg0B{}
	defer func() {
		jxMsg = &jiuxing.Package{
			Cmd:        byte(0x0b),
			Sn:         in.Sn,
			Encryption: in.Encryption,
			PackageLen: 0,
			Payload:    []uint8{},
			Check:      0,
		}
		resp.Tm = formatJxTime()
		jxMsg.Payload = resp.Encode()
		jxMsg.PackageLen = uint16(len(jxMsg.Payload))
	}()

	resp.TimeOutCnt = byte(0)

	return
}

func beachHand0C(nc *svc.ServiceContext) {
	for {
		select {
		case pack := <-channel0C:
			msg := jiuxing.Msg0C{
				Tm:         []byte{},
				TimeoutCnt: 0,
				PlugNum:    0,
				Plugs:      []jiuxing.PlugMode{},
			}
			msg.Decode(pack.Payload)
			logx.Infof("msg0C%+v", msg)
		case <-time.After(500 * time.Millisecond):

		}
	}
}

func init() {
	HandlerMap[uint8(0x0C)] = handle0C
}
